在使用隧道HTTP过着中涉及ip的两种模式,即Proxy-Tunnel自主切换IP,该模式适合一些需要登陆、Cookie缓存处理等爬虫需要精确控制IP切换时机的业务。 爬虫程序可以通过设置HTTP头Proxy-Tunnel: 随机数, 当随机数相同时,访问目标网站的代理IP相同。 比如: 需要登录,获取数据两个请求在一个IP下,只需对这组请求设置相同Proxy-Tunnel,例如:Proxy-Tunnel: 12345, 该组请求在代理有效期内使用相同的代理IP。 但是需要注意的是同一时间不同请求组可以设置不同Proxy-Tunnel: 随机数,并发完成数据爬取。
Proxy-Tunnel自主切换IP: 该模式适合一些需要登陆、Cookie缓存处理等爬虫需要精确控制IP切换时机的业务。 爬虫程序可以通过设置HTTP头Proxy-Tunnel: 随机数, 当随机数相同时,访问目标网站的代理IP相同。 例如:需要登录,获取数据两个请求在一个IP下,只需对这组请求设置相同Proxy-Tunnel,例如:Proxy-Tunnel: 12345, 该组请求在代理有效期内使用相同的代理IP。 注意:同一时间不同请求组可以设置不同Proxy-Tunnel: 随机数,并发完成数据爬取。 # 设置IP切换头(根据需求) tunnel = random.randint(1,10000) request.headers['Proxy-Tunnel
解决方案:巧妙利用Proxy-Tunnel头按需切换区别于常规的请求头,Proxy-Tunnel头直接作用于建立隧道的CONNECT请求阶段,代理服务器会根据这个头的值来决定是否分配全新的出口IP。 在登录阶段,我们可以固定Proxy-Tunnel的值。 值为"12345",确保验证码和登录请求在同一个IP上request.SetHeaderValue("Proxy-Tunnel","12345");browser.LoadRequest(request IP切换控制Proxy-Tunnel传入随机字符串触发分配新IP;传入固定字符串维持当前IP不变。 如果返回的5个IP均不相同,说明Proxy-Tunnel动态切换机制运行完美。灰度抓取测试:对比配置代理前后的行情网站HTTP响应状态码,确认403/429等被封禁的错误率是否断崖式下降。
采用Proxy-Tunnel自主切换IP: 该模式适合一些需要登陆、Cookie缓存处理等爬虫需要精确控制IP切换时机的业务。 爬虫程序可以通过设置HTTP头Proxy-Tunnel: 随机数, 当随机数相同时,访问目标网站的代理IP相同。 例如 :需要登录,获取数据两个请求在一个IP下,只需对这组请求设置相同Proxy-Tunnel,例如:Proxy-Tunnel: 12345, 该组请求在代理有效期内使用相同的代理IP。 注意 :同一时间不同请求组可以设置不同Proxy-Tunnel: 随机数,并发完成数据爬取。 2、设置相同Proxy-Tunnel,有些库封装比较高层次,请务必确认向代理发送了该HTTP头。
/bin/bash curl -H "Proxy-Tunnel: 12345" -v -x http://username:password@ip:port http://current.ip.16yun.cn :802 自定义隧道:可以在请求头中加入 Proxy-Tunnel: 数值*随机数值*, 不同的数值表示不同的隧道;在代理有效期内,当数值相同,使用的代理IP就相同 const http = require path: targetUrl, method: "GET", headers: { "Host": urlParsed.hostname, "Proxy-Tunnel
如需要每个请求强制切换IP,可以设置Proxy-Connection: Close和Connection: Close Proxy-Tunnel保持IP不变: #! "https": proxyMeta, } # 设置IP切换头 tunnel = random.randint(1, 10000) headers = {"Proxy-Tunnel HTTPAdapter, self).proxy_headers(proxy) if hasattr(self, 'tunnel'): headers['Proxy-Tunnel
第三次访问会cookie与ip绑定传入调用类的代理,返回cookie和代理(如果代理过期有变化返回新代理,后续流程携带新代理进行请求),这里我的python程序会使用aiohttp 通过设置代理IP和Proxy-Tunnel connector, headers={"User-Agent": userAgent}) as session: while True: # 随机设Proxy-Tunnel 并设置超时时间为3秒 async with session.get(targetUrl, timeout=3, proxy=proxyServer, proxy_headers={"Proxy-Tunnel
一般需要进行登陆后再操作的网站在爬取的时候对IP的限制都是比较严的,这种情况下就需要添加代理IP池,建议可以选择亿牛云提供的爬虫隧道加强版IP池,因为可以设置用户自主切换IP,爬虫程序可以通过设置HTTP头Proxy-Tunnel _tunnel_headers['Proxy-Tunnel'] = self.proxy_tunnel class HTTPSHandler(urllib2.HTTPSHandler): , "https": proxyMeta, } # 设置IP切换头 tunnel = random.randint(1, 10000) headers = {"Proxy-Tunnel
代理在Jsoup真中共的使用过程如下所示,在使用过程中要注意JSoup默认会关闭连接 访问HTTP网站请通过设置相同Proxy-Tunnel来保持相同的外网IP. .16yun.cn"; final static Integer ProxyPort = 31111; // 设置IP切换头 final static String ProxyHeadKey = "Proxy-Tunnel new PasswordAuthentication(ProxyUser, ProxyPass.toCharArray()); } }); // 设置Proxy-Tunnel
request, _ := http.NewRequest("GET", targetURI, bytes.NewBuffer([] byte(``))) // 设置Proxy-Tunnel time.Now().UnixNano()) // tunnel := rand.Intn(10000) // request.Header.Set("Proxy-Tunnel
http": proxyMeta, "https": proxyMeta, } # 设置IP切换头 tunnel = random.randint(1, 10000) headers = {"Proxy-Tunnel super(HTTPAdapter, self).proxy_headers(proxy) if hasattr(self, 'tunnel'): headers['Proxy-Tunnel
http”: proxyMeta, “https”: proxyMeta, } # 设置IP切换头 tunnel = random.randint(1, 10000) headers = {“Proxy-Tunnel proxy): headers = super(HTTPAdapter, self).proxy_headers(proxy) if hasattr(self, ‘tunnel’): headers[‘Proxy-Tunnel
final static Integer ProxyPort = 31111; // 设置IP切换头 final static String ProxyHeadKey = "Proxy-Tunnel PasswordAuthentication(ProxyUser, ProxyPass.toCharArray()); } }); // 设置Proxy-Tunnel
final static Integer ProxyPort = 31111; // 设置IP切换头 final static String ProxyHeadKey = "Proxy-Tunnel PasswordAuthentication(ProxyUser, ProxyPass.toCharArray()); } }); // 设置Proxy-Tunnel
request, _ := http.NewRequest("GET", targetURI, bytes.NewBuffer([] byte(``))) // 设置Proxy-Tunnel rand.Seed(time.Now().UnixNano()) // tunnel := rand.Intn(10000) // request.Header.Set("Proxy-Tunnel
request, _ := http.NewRequest("GET", targetURI, bytes.NewBuffer([] byte(``))) // 设置Proxy-Tunnel time.Now().UnixNano()) // tunnel := rand.Intn(10000) // request.Header.Set("Proxy-Tunnel
https.proxyPassword", ProxyPass); // 设置IP切换头 final static String ProxyHeadKey = "Proxy-Tunnel "; // 设置Proxy-Tunnel Random random = new Random(); int tunnel =
.16yun.cn"; final static Integer ProxyPort = 31111; // 设置IP切换头 final static String ProxyHeadKey = "Proxy-Tunnel new PasswordAuthentication(ProxyUser, ProxyPass.toCharArray()); } }); // 设置Proxy-Tunnel
"http": proxyMeta, "https": proxyMeta,}# 设置IP切换头tunnel = random.randint(1, 10000)headers = {"Proxy-Tunnel super(HTTPAdapter, self).proxy_headers(proxy) if hasattr(self, 'tunnel'): headers['Proxy-Tunnel
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy); // 设置Proxy-Tunnel ); // int tunnel = random.nextInt(10000); // connection.setRequestProperty("Proxy-Tunnel